using System;
using JetBrains.Annotations;
using Kaleida.ServiceMonitor.Framework;

namespace Kaleida.ServiceMonitor.Model.Runtime
{
    public static class PollIntervalCriteria
    {
        private static TimeSpan minimumTimespan = TimeSpan.FromMilliseconds(10);

        [NotNull]
        public static Duration EnsureMet([NotNull] Duration duration)
        {
            if (duration == null) throw new ArgumentNullException("duration");

            return Accepts(duration)
                       ? duration
                       : new Duration(minimumTimespan.TotalMilliseconds, "ms");
        }

        public static bool Accepts([NotNull] Duration duration)
        {
            if (duration == null) throw new ArgumentNullException("duration");
            return duration.ToTimeSpan() >= minimumTimespan;
        }

        public static string GetSummary()
        {
            return string.Format("Minimum interval is {0} ms", minimumTimespan.TotalMilliseconds);
        }
    }
}